cmake_minimum_required(VERSION 3.2)
project(CVM C CXX)

set(CMAKE_CXX_FLAGS "-std=c++14 -fPIC")

#include directories
include_directories("include")

# Tests
set(TEST_EXECS "")
file(GLOB TEST_SRCS tests/cpp/*.cc)
find_path(GTEST_INCLUDE_DIR gtest/gtest.h)
find_library(GTEST_LIB gtest "$ENV{GTEST_LIB}")

if(GTEST_INCLUDE_DIR AND GTEST_LIB)
	foreach(__srcpath ${TEST_SRCS})
		get_filename_component(__srcname ${__srcpath} NAME)
		string(REPLACE ".cc" "" __execname ${__srcname})
		add_executable(${__execname} ${__srcpath})
		list(APPEND TEST_EXECS ${__execname})
		target_include_directories(${__execname} SYSTEM PUBLIC ${GTEST_INCLUDE_DIR})
		target_link_libraries(${__execname} PRIVATE ${TVM_TEST_LIBRARY_NAME} ${GTEST_LIB} pthread dl)
		set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_ALL 1)
		set_target_properties(${__execname} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
	endforeach()
	add_custom_target(cpptest DEPENDS ${TEST_EXECS})
endif()